package com.virgo.demo.support.controller.admin;

import com.virgo.common.entity.IResponse;
import com.virgo.demo.core.annotation.Log;
import com.virgo.demo.support.domain.bo.ConfigBo;
import com.virgo.demo.support.domain.vo.ConfigVo;
import com.virgo.demo.support.service.ConfigService;
import com.virgo.limit.annotation.RepeatSubmit;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/manage168/config")
@RequiredArgsConstructor
public class ConfigController {

	private final ConfigService configService;

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	@Log(module = "基础配置", type = "编辑", permission = "config_save")
	@RepeatSubmit
	public IResponse<Void> saveAction(@Validated ConfigBo configBo) {
		configBo.setConfigGroup(1);
		configService.saveConfig(configBo);
		return IResponse.ok();
	}

	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@Log(permission = "config_list", saveLog = false)
	public IResponse<List<ConfigVo>> listAction() {
		return IResponse.ok(configService.findList(1));
	}
}